package com.woniuxy.hrp.service.Serviceimpl;

import com.woniuxy.hrp.entity.*;
import com.woniuxy.hrp.mapper.WalletMapper;
import com.woniuxy.hrp.mapper.WalletoprMapper;
import com.woniuxy.hrp.service.WalletoprService;
import com.woniuxy.hrp.utils.QueryUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @program: hrph
 * @ClassName WalletoprServiceImpl
 * @description:
 * @author: LRW
 * @create: 2022-09-01 00:51
 * @Version 2.0
 **/
@Service
public class WalletoprServiceImpl implements WalletoprService {

    @Autowired
    private WalletoprMapper walletoprMapper;

    @Autowired
    private WalletMapper walletMapper;

    /***
     * @description: 多条件分页查询指定患者的钱包明细
     * @param:walletoprVo（患者id,当前页，每页条数，查询条件）
     * @return: java.util.List<com.woniuxy.hrp.entity.Walletopr>
     * @author Lrw
     * @date: 2022/9/1 1:22
     */
    @Override
    public PageBean<Walletopr> getWalletoprsByPatientIdAndConditionAndPage(int patientId,int pageSize,int page,Walletopr walletopr) {
        int walletId = walletMapper.getByPatientId(patientId).getId(); //根据患者id查钱包id
        Wallet wallet = new Wallet();
        wallet.setId(walletId);
        walletopr.setWallet(wallet);//将患者id对应的钱包id封装进查询条件
        List<Walletopr> list = walletoprMapper.selectByCondition(walletopr);
        if (list != null){
            List<Walletopr> data = QueryUtil.getByPage(list, pageSize, page);//获取当前页数据
            PageBean<Walletopr> pageBean = new PageBean<>();
            pageBean.setData(data);
            pageBean.setTotalNums(list.size());
            pageBean.setTotalPages((list.size() + pageSize -1) / pageSize);
            return pageBean;
        }
        return null;
    }
    @Override
    public void add(Walletopr walletopr) {
        walletoprMapper.add(walletopr);
    }

//    public static List<Walletopr> getByPage(List<Walletopr> dataList, int pageSize,int currentPage) {
//        List<Walletopr> currentPageList = new ArrayList<>();
//        if (dataList != null && dataList.size() > 0) {
//            int currIdx = (currentPage > 1 ? (currentPage - 1) * pageSize : 0);
//            for (int i = 0; i < pageSize && i < dataList.size() - currIdx; i++) {
//                Walletopr data = dataList.get(currIdx + i);
//                currentPageList.add(data);
//            }
//        }
//        return currentPageList;
//    }


}
